﻿var currentPage = 1; // 当前页
var pageSize = 18; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数
var type = 0;

$(document).ready(function() {
    var startday = LexunJS.GetQueryString("addDate1");
    var endday = LexunJS.GetQueryString("addDate2");
    var deptid = LexunJS.GetQueryString("deptid");

    var salesmanid = LexunJS.GetQueryString("salesmanid");

    if (startday != "")
        $("#StartTime").val(startday);
    if (endday != "")
        $("#EndTime").val(endday);

    $('#utxdeptid').val(deptid);
    $('#utxtsub').val(salesmanid);

    ShowFollowList(currentPage);
});

function ShowFollowList(currentPage) {
    $("#divList").html(""); // 清空列表
    $("#divPage").html(""); // 清空分页
    var deptname = document.getElementById("umainclass").value;
    
    
    var deptid = document.getElementById("utxdeptid").value;
    
    var startTime = document.getElementById("StartTime").value;
    var EndTime = document.getElementById("EndTime").value;
    var UserName = document.getElementById("utxtsub").value;
    var ftype = LexunJS.GetQueryString("ftype");                // 带看房 待看提醒...
    type = 1;
    $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表 

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerCustomer.ashx',
        data: 'act=p_CustomerAlertReportList&deptname=' + deptid + '&startTime=' + escape(startTime) + '&EndTime=' + escape(EndTime) + '&UserName=' + escape(UserName) + '&ftype=' + ftype + '&page=' + currentPage + '&pagesize=' + pageSize,
        timeout: '10000',
        error: function() {
            alert("修改失败！");
        },
        success: function(json) {
            ShowFlowCallBack(json);
        }
    });
}

function ShowFlowCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    var page = json.page;
    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    if (record == null || record.length == 0) {
        $("#divList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    $("#divList").html(""); // 显示列表
    var arr = [];
    arr.push("<table id='table2' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("客/盘源编号");
    arr.push("</td>");
    arr.push("<td height='25'bgcolor='d3eaef' class='STYLE10'>");
    arr.push("提醒时间</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("提醒内容</td>");
    arr.push("<td height='25'  bgcolor='d3eaef' class='STYLE10'>");
    arr.push("添加人</td>");
    arr.push("<td height='25'  bgcolor='d3eaef' class='STYLE10'>");
    arr.push("添加部门</td>");
    arr.push("<td height='25'  bgcolor='d3eaef' class='STYLE10'>");
    arr.push("添加时间</td>");
    arr.push("<td height='25'  bgcolor='d3eaef' class='STYLE10'>");
    arr.push("带看时间</td>");   
    arr.push("<td height='25' bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("人员</td>");
    arr.push("<td height='25' bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("部门</td>");
    arr.push("</tr>");

    for (var i = 0; i < record.length; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;'  onclick=\"selectedTr('" + record[i].id + "')\">");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;'  onclick=\"selectedTr('" + record[i].id + "')\">");
        arr.push("<td height='25'  class='STYLE10'>");
        if (record[i].type==2)
            arr.push("<a href='javascript:ShowDialogs(\"../PM/CustomerDetails.aspx\",\"" + record[i].housingid + "\");'>" + record[i].housingid + "</a>");
        else if (record[i].type == 1)
            arr.push("<a href='javascript:ShowDialog_Housing(\"../PM/HousingDetail.aspx\",\"" + record[i].housingid + "\");'>" + record[i].housingid + "</a>");
        arr.push("</td>");        
        arr.push("<td height='25' class='STYLE10'>");
        arr.push("" + record[i].alertdate + "</td>");
        arr.push("<td height='25' style='text-align: left;' class='STYLE10'>");
        arr.push("" + record[i].alertcontent + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].adduser + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].adddept + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].adddate + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].ddate + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].duser + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].ddept + "</td>")
        arr.push("</tr>");
    }
    arr.push("</table>");
    
    $("#divList").html(arr.join('')); // 显示列表
    $("#divPage").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage(currentPage, pageall, "ShowFollowList");  // 分页
        $("#divPage").html(pageHtml);
    }
}

// 选中某行
function selectedTr(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");
}

//弹出窗口
function ShowDialogs(url, id) {
    //var path = "../CM/" + url + "?id=" + id;
    //var parameter = "客源跟进";
    //var style = "dialogWidth:660px; dialogHeight:400px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    //window.showModalDialog(path, parameter, style);

    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");
    
    self.parent.closeTab('客源详情');
    self.parent.addTab('客源详情', "../CM/CustomerDetail.aspx?id=" + id + "&tagNo=4", 'icon-nav');
}


//弹出窗口
function ShowDialog_Housing(url, id) {
    //var path = "../CM/" + url + "?id=" + id;
    //var parameter = "客源跟进";
    //var style = "dialogWidth:660px; dialogHeight:400px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    //window.showModalDialog(path, parameter, style);

    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    self.parent.closeTab('盘源详情');
    self.parent.addTab('盘源详情', "../PM/HousingDetail.aspx?id=" + id + "&tagNo=8", 'icon-nav');
}